from datetime import timedelta
from utils.operators.spark_sql_operator import SparkSqlOperator
from jms.ods.oms.yl_oms_oms_waybill import jms_ods__yl_oms_oms_waybill
from jms.dwd.dwd_order_source_update_sync_dt import jms_dwd__dwd_order_source_update_sync_dt

jms_dwd__dwd_order_source_detail_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_order_source_detail_dt',
    email=['suning@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dwd__dwd_order_source_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_order_source_detail_dt/execute.hql',
    pool_slots=4,
    executor_cores=4,
    executor_memory='20G',
    driver_memory='4G',
    num_executors=25,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.maxExecutors': 40,
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.dynamicallocation.enabled': 'true',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,
          'spark.shuffle.service.enabled': 'true',
          'spark.sql.shuffle.partitions': 600
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 20,
              'hive.exec.max.dynamic.partitions': 20
    },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dwd__dwd_order_source_detail_dt << [
    jms_ods__yl_oms_oms_waybill,
    jms_dwd__dwd_order_source_update_sync_dt
]
